﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;

/// <summary>
/// Summary description for LoginUser
/// </summary>
public static class LoginUser
{
    public static bool IsSecurePatient(string year, string tel, string pre_code)
    {
        string connectionName = string.Format("ConnectionString{0}", year.Replace("/", ""));
        DataClassesDataContext dataCotext = new DataClassesDataContext(ConfigurationManager.ConnectionStrings[connectionName].ConnectionString);
        var datein = from unHealths in dataCotext.UnHealths.Where(
                        b => (b.pre_code == pre_code && b.tel == tel && b.datein.StartsWith(year)))
                     select unHealths.datein;
        if (datein.Count() < 1)
            return false;
        return true;
    }
    public static bool IsSecure(string password, string username, string year, byte role)
    {
        string connectionName = string.Format("ConnectionString{0}", year.Replace("/", ""));
        DataClassesDataContext dataCotext = new DataClassesDataContext(ConfigurationManager.ConnectionStrings[connectionName].ConnectionString);
        var user = from login in dataCotext.Logins.Where(
                        b => (b.UserName == username && b.Password == password && b.RoleID == role))
                   select string.Format("{0} {1}",login.FirstName,login.LastName);
        if (user.Count() < 1)
            return false;
        return true;
    }
    public static bool IsSecure(string password, string username)
    {
        return true;

       // DefaultEntityConnection defaultEntityConnection = new DefaultEntityConnection();
        //TODO Change it
      //  return defaultEntityConnection.Users.Where(user => user.UserName == username).First() != null;//&& user.Password == "123");
    }
}